package com.kexinde.wjifen.aop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

import com.kexinde.wjifen.model.Shopkeeper;
import com.opensymphony.xwork2.ActionContext;

@Component("NoramlUserAuthority")
public class NoramlUserAuthority {

	private HttpServletRequest request;

	public String check(ProceedingJoinPoint pjp) throws Throwable {
		request = (HttpServletRequest) ActionContext.getContext().get(
				ServletActionContext.HTTP_REQUEST);
		HttpSession session = request.getSession();
		// NormalUser normalUser=(NormalUser)
		// session.getAttribute("normalUser");
		// if(normalUser!=null){
		// pjp.proceed();
		// }

		Shopkeeper normalUser = (Shopkeeper) session.getAttribute("shopkeeper");
		if (normalUser != null) {
			if("loginsuccess".equals(pjp.proceed()))
				return "loginsuccess";
			else return "loginfail";
		} else {
			System.out.println("*@@!@!*@!*@!(*@!*(no shopkeeper!");
			return "loginfail";
		}
	}
}
